<?php


namespace App\Admin\Controller\AdminUser;


use App\Admin\Controller\AdminBaseController;
use App\Admin\Requests\AdminUser\UserCreateRequest;
use App\Admin\Requests\AdminUser\UserUpdatePasswordRequest;
use App\Admin\Requests\AdminUser\UserUpdateRequest;
use App\Admin\Services\AdminUser\AdminUserService;
use Illuminate\Http\Request;

class UserController extends AdminBaseController {
    private $_service;

    public function __construct(AdminUserService $service) {
        $this->_service = $service;
    }

    /**
     * 远程搜索用户列表
     *
     * @param Request $request
     * @return mixed
     */
    public function searchByQuery(Request $request) {
        return $this->success($this->_service->searchByQuery($request));
    }

    /**
     * 用户分页列表
     *
     * @return mixed
     */
    public function page() {
        return $this->success($this->_service->page());
    }

    /**
     * 新建用户
     *
     * @param UserCreateRequest $request
     * @return mixed
     */
    public function store(UserCreateRequest $request) {
        return $this->success($this->_service->store($request));
    }

    /**
     * 更新用户信息
     *
     * @param $id
     * @param UserUpdateRequest $request
     * @return mixed
     * @throws \Exception
     */
    public function update($id, UserUpdateRequest $request) {
        return $this->success($this->_service->update($id, $request));
    }

    /**
     * 删除用户
     *
     * @param $id
     * @return mixed
     * @throws \Exception
     */
    public function delete($id) {
        return $this->success($this->_service->delete($id));
    }

    /**
     * 更新用户密码
     *
     * @param $id
     * @param UserUpdatePasswordRequest $request
     * @return mixed
     * @throws \Exception
     */
    public function updatePassword($id, UserUpdatePasswordRequest $request) {
        return $this->success($this->_service->update($id, $request));
    }

}